const now = Date.parse(new Date())

// 校验手机号
export const isPhoneNumber = (str) => {
  let reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/
  return reg.test(str)
}

// 获取时间间隔
export const interval = (targetTime) => {
  if (!targetTime){
    return ''
  } else {
    targetTime = targetTime.substring(0, 19);
    targetTime = targetTime.replace(/[\/|\-]/g, '/');
    let targetTimestamp = new Date(targetTime).getTime();
    let timeInterval = (now - targetTimestamp) / 1000
    console.log(timeInterval)
    if (timeInterval < 60) {
      return '刚刚'
    } else if (timeInterval < 3600) {
      let minutes = Math.floor(timeInterval / 60)
      return minutes + ' 分钟以前'
    } else if (timeInterval < 43200) {
      let hours = Math.floor(timeInterval / 3600)
      return hours + ' 小时以前'
    } else if (43200 < timeInterval && timeInterval < 86400){
      return '昨天'
    } else{
      return targetTime.substring(0, 16);
    }
  }
}

